/**
 * Multicast project Bidois Morgan & Thomas Nunes
 *
 */
package Gui;

import Test.ExecuteServer;

/**
 *
 * @author thomas
 */
public class ServerGUI extends javax.swing.JFrame {

    private int total;
    private int clientwait;
    private ExecuteServer father;

    /**
     * Creates new form ServerGUI
     */
    public ServerGUI(ExecuteServer papa) {
        father = papa;
        initComponents();
        this.setClientWait(0);
        this.setTotal(0);
    }

    public void setTotal(int to) {
        total = to;
        this.jLabeltotalclient.setText(to + "");
    }

    public void setClientWait(int cw) {
        clientwait = cw;
        this.jLabelclientwait.setText(cw + "");
    }

    public void updateCorrectLbl(boolean ordered, int lc) {
        if (ordered) {
            this.jTextArea1.setText(this.jTextArea1.getText() + "\nLes Clients  ordonnés à C"+lc);
        } else {
            jTextArea1.setText(this.jTextArea1.getText() + "\n Les Clients non ordonnés à C"+lc);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jjLabel1 = new javax.swing.JLabel();
        jLabelclientwait = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabeltotalclient = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButtonBURST = new javax.swing.JButton();
        jButtonSTOP = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButtonKill = new javax.swing.JButton();
        jButtonAnalyse = new javax.swing.JButton();
        lblCorrect = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        getContentPane().add(jScrollPane1);

        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));

        jjLabel1.setText("Clients connected");

        jLabelclientwait.setText("0");

        jLabel3.setText("Number total of client Waited");

        jLabeltotalclient.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jjLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelclientwait))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                        .addComponent(jLabeltotalclient)))
                .addContainerGap(99, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jjLabel1)
                    .addComponent(jLabelclientwait))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabeltotalclient))
                .addContainerGap(60, Short.MAX_VALUE))
        );

        jPanel3.add(jPanel1);

        jButtonBURST.setText("BURST");
        jButtonBURST.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBURSTActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonBURST);

        jButtonSTOP.setText("STOP");
        jButtonSTOP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSTOPActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonSTOP);

        jButton1.setText("KILL All !");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);

        jButtonKill.setText("KILL a client");
        jButtonKill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonKillActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonKill);

        jButtonAnalyse.setText("Analyse clients");
        jButtonAnalyse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAnalyseActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonAnalyse);
        jPanel2.add(lblCorrect);

        jPanel3.add(jPanel2);

        getContentPane().add(jPanel3);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAnalyseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAnalyseActionPerformed
        father.askForHistoric();
    }//GEN-LAST:event_jButtonAnalyseActionPerformed

    private void jButtonKillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonKillActionPerformed
        father.killSomeone();
        this.setClientWait(clientwait--);

    }//GEN-LAST:event_jButtonKillActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        for (int i = 0; i <= total + 4; i++) {
            father.killSomeone();
        }
        System.exit(1);
    }//GEN-LAST:event_jButton1ActionPerformed
boolean burst = false;
    private void jButtonBURSTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBURSTActionPerformed
        if (!burst){
            burst=true;
            this.father.startBurst();
        }
    }//GEN-LAST:event_jButtonBURSTActionPerformed

    private void jButtonSTOPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSTOPActionPerformed
       if (burst)
           this.father.stopBurst();
       burst = false;
    }//GEN-LAST:event_jButtonSTOPActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAnalyse;
    private javax.swing.JButton jButtonBURST;
    private javax.swing.JButton jButtonKill;
    private javax.swing.JButton jButtonSTOP;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelclientwait;
    private javax.swing.JLabel jLabeltotalclient;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel jjLabel1;
    private javax.swing.JLabel lblCorrect;
    // End of variables declaration//GEN-END:variables
}
